import time
import threading
from queue import Queue
import global_variable as gl

################################################################################################################
"""数据显示"""
###############################################################################################################
gl.flag_init()
gl.dec_init()
gl.RaspInit()
gl.identify_init()
POSE = ["Unknow","Fist-Bumps","Angry","Happy","Disagree","SitDown","Hello","Agree","Shoot","Bye","Pink Up","Thumb Up","Fuck","OK","love","Rock'n'Roll"]
NAME = ['ChenGuo', 'ChenYJ', 'DaBing', 'FuCheng', 'KouZY', 'LiangDW', 'LiuBing', 'Rambo', 'TuJian', 'YanCL', 'ZhuXH']
class CollectData:
    def __init__(self, Name = "Unknow", HandPos = "Unknow",VoiceComd = "Unknow",Tactile = 0) -> None:
        self._name = Name
        self._hand = HandPos
        self._voice = VoiceComd
        self._tactile = Tactile # 0:无触觉 1:有触觉
    def Show(self):
        print("-------------------------")
        print("Name: ",self._name)
        print("Pose: ",self._hand)
        print("Command: ",self._voice)
        print("Tactile: ",self._tactile)
        print("-------------------------")
    def Str(self):
        name = ""
        name += "Name: "
        name +=self._name
        pose = ""
        pose +="Pose: "
        pose +=self._hand
        comd = ""
        comd +="Command: "
        comd +=self._voice
        tact = ""
        tact += "Tactile: "
        tact += str(self._tactile)
        SPACE = "\n\r"
        identity = name+ SPACE+pose+SPACE+comd+SPACE+tact
        return [identity,name,pose,comd,tact]
# IdentityInform = Queue(1)
class ShowThread(threading.Thread):
    def __init__(self,ThreadID):
        threading.Thread.__init__(self)
        self.ThradID = ThreadID
    def run(self):
        print("线程id: ", self.ThradID)
        print("数据发送")
        global index_name,index_pos
        index_pos=0
        index_name=0
        while gl.get_flag():
            cl = CollectData()
            if not gl.get_face_name().empty():
                index_name = gl.pop_face_name()
                cl._name = NAME[index_name]
            if not gl.get_hand_gesture().empty():
                index_pos = gl.pop_hand_gesture()
                cl._hand = POSE[index_pos]
            if not gl.get_identify().full():
                gl.put_identify(cl.Str())
                # print(cl.Str())
            # cl.Show()
            dec = (index_name<<16) | (index_pos)
            gl.dec_set(dec)
            if dec != 0:
                msg = "1_"+str(int(dec))+"_"+"-1_-1#"
                print(msg)
                gl.Get_Rasp().send(msg)
            time.sleep(2)
################################################################################################################